package simple;

import java.io.InputStream;
import java.util.ArrayList;

public abstract class GpsReader extends Thread {
	private InputStream inputStream;
	private boolean isActive;
	private ArrayList<IGpsListener> gpsListeners;
	
	protected ArrayList<IGpsReaderListener> listeners;
	
	public GpsReader(InputStream inputStream){
		this.inputStream = inputStream;
		this.isActive = false;
		
		this.listeners = new ArrayList<IGpsReaderListener>();
		
		this.gpsListeners = new ArrayList<IGpsListener>();
	}
	
	public boolean isActive() {
		return isActive;
	}
	
	public void activate(){
		this.isActive = true;
		for (IGpsReaderListener listener : listeners) {
			listener.Activated(new GpsReaderEvent(this));
		}
		this.start();
	}
	
	public void deactivate(){
		this.isActive = false;
		for (IGpsReaderListener listener : listeners) {
			listener.Deactivated(new GpsReaderEvent(this));
		}
	}

	public InputStream getInputStream(){
		return this.inputStream;
	}
	
	public Iterable<IGpsListener> getGpsListeners(){
		return this.gpsListeners;
	}
	
	public void addGpsListener(IGpsListener listener){
		this.gpsListeners.add(listener);
	}
	public void removeGpsListener(IGpsListener listener){
		this.gpsListeners.remove(listener);
	}
	public void clearGpsListeners(){
		this.gpsListeners.clear();
	}
}
